package com.zust.java.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zust.java.bean.Account;
import com.zust.java.bean.JobShop;
import com.zust.java.dao.imp.AccountDaoImp;
import com.zust.java.dao.imp.JobShopDaoImp;

@Service
public class LoginService {

	@Autowired
	private Account account;
	@Autowired
	private AccountDaoImp adi;
	@Autowired
	private JobShop jobShop;
	@Autowired
	private JobShopDaoImp jsdi;
	
	public Map<String, Account> checkLogin(int acco, String password, int type) {
		account.setAccount(acco);
		account.setPassword(password);
		account.setType(type);
		Map<String, Account> map = new HashMap<String, Account>();
		List<Object> list = new ArrayList<Object>();
		String ref = null;
		
		list =  adi.select(account);
		System.out.println("loginService: " + list);
		if (list.contains(null)) {
			ref = "error";
		} else {
			ref = (type == 1) ? "producer/producer" : "processor/processor";
			account = (Account) list.get(0);
		}
		map.put(ref, account);
		return map;
	}
	
	public JobShop findJobShop(int accountId) {
	    return jsdi.selectByAccountId(accountId);
	}
}
